package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerDao customerDao;

    @Override
    public Map<String, Object> customerList(Integer page, Integer rows, String customerName) {
        HashMap<String, Object> map = new HashMap<>();
        Long total = customerDao.getTotal(customerName);
        List<Customer> customerList= customerDao.list((page-1)*rows,rows,customerName);
        map.put("rows",customerList);
        map.put("total",total);
        return map;
    }

    @Override
    public void saveOrUpdate(Long customerId, Customer customer) {
        if(ObjectUtils.isEmpty(customerId)){
            customerDao.save(customer);
        }else{
            customerDao.update(customer,customerId);
        }
    }

    @Override
    public void delete(List ids) {
        customerDao.delete(ids);
    }
}
